<?php

/**
 * This is the model class for table "collection".
 */
class collection extends CModel
{
	/**
	 * The followings are the available columns in table 'collection':
	 * @var integer $id
	 * @var integer $shipper_id
	 * @var integer $consignee_id
	 * @var integer $req_date
	 * @var integer $collect_date
	 * @var integer $pkg_id
	 * @var integer $wt_id
	 * @var integer $m3_id
	 * @var string $remark
	 */

	/**
	 * Returns the static model of the specified AR class.
	 * @return collection the static model class
	 */
         public $shipper, $shipper_add, $shipper_contact, $delivery, $delivery_add, $delivery_contact;
         public $date, $tools, $remark, $pkg;
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('shipper, date,pkg', 'required'),
			array('date','type','type'=>'date','dateFormat'=>'dd/MM/yyyy'),
			array('shipper_add, delivery_add, remark','length','max'=>250),
			array('shipper_contact, delivery_contact, shipper, delivery, tools, pkg','length','max'=>125),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
		);
	}
	
	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'shipper' => 'Shipper name',
			'collect_date' => 'Collect Date',
			'address_id' => 'Address to collect',
			'remark' => 'Remark',
			'company_id'=>'Shipper',
			'consignee_id'=>'Consignee',
			'contacts'=>'Contacts',
		);
	}
        
        public function  attributeNames() {
            return array(
                'shipper_add',
                'delivery_add',
                'shipper',
                'delivery',
                'shipper_contact',
                'delivery_contact',
                'pkg',
                'tools',
                'remark',
                'date',
                'cargo_id'
            );
        }

        public function save(){
            if(!$this->validate())
                return false;
            $pdf = new makePdf;
            $pdf->renderPartial('/collection/reportPDF', array('data'=>$this));
            $filename = $pdf->stream('subcert');
        }

}